package gui;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import javax.swing.JLabel;

/**
 * @author Ramy Refky 
 * */
public class CustomComponentLabel extends ComponentLabel{

	private static final long serialVersionUID = 1L;

	JLabel customLabel;
	JLabel specsLabel;
	int clockHeight;
	
	/**
	 * Constructor initializes ComponentLabel.
	 * @param XLocation, YLocation, Width, Height
	 */
	public CustomComponentLabel(int xLoc,int yLoc,int originalWidth, int originalHeight){
		super(xLoc,yLoc,originalWidth,originalHeight);

		clockHeight=0;
	
		customLabel = new JLabel("",JLabel.CENTER);
		customLabel.setBounds(0,newHeight/3,newWidth,15);
		add(customLabel);
		
		specsLabel = new JLabel("",JLabel.CENTER);
		specsLabel.setBounds(0,newHeight*2/3,newWidth,15);
		add(specsLabel);
		
		repaint();
	}
	@Override
	public void zoomAdjust(Double zoomFactor){
		newWidth=(int) (originalWidth*zoomFactor);
		newHeight=(int) (originalHeight*zoomFactor);
		setBounds(0,0,newWidth,newHeight);
		customLabel.setBounds(0,newHeight/3,newWidth,15);
		specsLabel.setBounds(0,newHeight*2/3,newWidth,15);
		repaint();
	}
	/**
	 * Sets the title of the CUSTOM Gate's label a given String text.
	 */
	public void setComponentText(String text){
		customLabel.setText(text);
		repaint();
	}
	/**
	 * Gets the title of the CUSTOM Gate's label.
	 * @return String
	 */
	public String getComponentText(){
		return customLabel.getText();
	}
	/**
	 * Sets the specs (details) a given String text.
	 */
	public void setSpecsText(String text){
		specsLabel.setText(text);
		specsLabel.setBounds(0,newHeight*2/3,newWidth,15);
		repaint();
	}
	/**
	 * Draws the clock symbol at a given height value.
	 */
	public void drawClockAtHeight(int height){
		clockHeight=height;
		repaint();
	}
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		

		Rectangle Box = new Rectangle();
		Box.setBounds(newWidth/6,2,newWidth*2/3,newHeight-4);
		
    	Graphics2D g2 = (Graphics2D)g;
    	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);
    	
        g2.setStroke(new BasicStroke(2f));
        
        g2.setPaint(Color.black);
        g2.draw(Box);
        
        if(!selected)
        	g2.setPaint(Color.white);
        else
        	g2.setPaint(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
        Box.setBounds(newWidth/6+1,3,newWidth*2/3-1,newHeight-5);
        
        g2.fill(Box);
        
        g2.setPaint(Color.black);
       
        if(clockHeight!=0){
        	
            g2.drawLine(newWidth/6+1,clockHeight-4,newWidth/6+7,clockHeight);
            g2.drawLine(newWidth/6+1,clockHeight+4,newWidth/6+7,clockHeight);
        }  
	}
}
